package zhihui.mobile.ui.shop;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

import zhihui.mobile.bean.shop.BannerInfo;
import zhihui.mobile.config.Config;

/**
 * Created by 张公铭 on 2017/7/24 0024.
 */

public class BannerAdapter extends StaticPagerAdapter
{
    private Context mContext;
    private List<BannerInfo> mList = new ArrayList<>();

    public BannerAdapter(Context context)
    {
        mContext = context;
    }

    public void setmList(List<BannerInfo> list)
    {
        if (mList == null)
        {
            mList = new ArrayList<>();
        }
        mList.clear();
        mList.addAll(list);
    }

    @Override
    public View getView(ViewGroup container, int position)
    {
        ImageView view = new ImageView(container.getContext());
        BannerInfo  bannerInfo = mList.get(position);
        ImageLoader.getInstance().displayImage(Config.FILE_URL + bannerInfo.getImg(), view);
        view.setScaleType(ImageView.ScaleType.FIT_XY);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        return view;
    }

    @Override
    public int getCount()
    {
        return mList.size();
    }

    public BannerInfo getItem(int position)
    {
        return mList.get(position);
    }
}
